n = int(input())
position=[]
for i in range(n):
    temp=list(map(int,input().split()))
    position.append(temp)
print(position)
def get_resulit(n,position):
    if n==1:
        return 0
    position.sort(key = lambda x:x[0])

    mid_pos= None
    if n%2 !=0:
        mid = int(n/2)
        mid_pos= sum(position[mid])/2
    else:
        midr= int(n/2)
        midl= midr-1
        mid_pos = (position[midl][1] + position[midr][0]) /2
    ans =0
    for post in position:
        l,r = post
        if l>mid_pos:
            ans+=l-mid_pos
        if r<mid_pos:
            ans+=mid_pos-r
    return int(ans)

print(get_resulit(n,position))